<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>钱包</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body >
<div id="app" class="container" v-cloak>
    <div  style="background-color: #0F80C7;color: #fff;">
        <div class="wallettopitem" style="font-size: 12px;">总资产估值(USDT)</div>
        <div class="wallettopitem">{{((parseFloat(user.balance)+parseFloat(user.frozen))*0.1).toFixed(2)}}</div>
        <div class="wallettopitem" style="font-size: 12px;">≈  ￥ {{((parseFloat(user.balance)+parseFloat(user.frozen))*0.64).toFixed(2)}}</div>
        <div class="walletbutton" style="padding-left: 8px;">
            <span class="walletspan" v-myclick="recharege">充币</span>
            <span class="walletspan" v-myclick="withdraw">提币</span>
        </div>
    </div>
    <div style="padding:5px 10px;background-color: #fff;">
        <div style="font-size: 14px;margin-top: 5px;">账户详情</div>
            <div class="accountline" style="border-bottom: 1px solid #F8F8FF">
            <div class="linetitle">CC</div>
            <div class="linecontainer">
                <div class="lineleft" style="float: left;width: 50%;">
                <div class="linetop">可用数量</div>
                <div class="linebottom">{{user.balance}}</div>
                </div>
                <div class="lineright" style="float: right;width: 50%;">
                    <div class="linetop">冻结</div>
                    <div class="linebottom">{{user.frozen}}</div>
                </div>
                <div style="clear: both;"></div>
            </div>

        </div>
        <div class="accountline">
            <div class="linetitle">CCB</div>
            <div class="linecontainer">
                <div class="lineleft" style="float: left;width: 50%;">
                <div class="linetop">可用数量</div>
                <div class="linebottom">{{user.ccb}}</div>
                </div>
                <div class="lineright" style="float: right;width: 50%;">
                    <div class="linetop">冻结</div>
                    <div class="linebottom">{{user.ccbfrozen}}</div>
                </div>
                <div style="clear: both;"></div>
            </div>

        </div>
    </div>

</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var user,
        qrcode,
        scanner,
        wx,
        qq,
        clipBoard,
        vm;

    var mq;
    apiready = function () {
        setBSImg();
        scanner = api.require('FNScanner');
        clipBoard = api.require('clipBoard');
        if(hasPrefs('user')){
            user = JSON.parse(getPrefs('user'));
            initApp();
            api.parseTapmode();
        }else{
            var data = {member_id: getPrefs('member_id')};
            var callback = function (ret) {

            user = ret.content;
            initApp();
            api.parseTapmode();
            setPrefs('user', user);
        };

        pinet.post(URL.getUserinfo, data, callback);
        }
        addListeners();
        setUserRefreshHeaderInfo(refresh);
    };


    function initApp() {
        vm = new Vue({
            el: '#app',
            data: {
                user: user,
                imgPath: '../../image/',
                appInstalled: {
                    wx: true,
                    qq: true,
                },
                BSImg: {
                    big: Vue.BSImg == 'big',
                    small: Vue.BSImg == 'small',
                },
            },
            computed: {
            },
            methods: {
                copyInvite: function (text) {
                    clipBoard.set({
                        value: text
                    }, function (ret) {
                        if (ret) {
                            api.toast({
                                msg: '已复制到剪贴板',
                            });
                        }
                    });
                },
                withdraw(){
                    api.actionSheet({
                    title: '选择提现币种',
                    cancelTitle: '取消',
                    buttons: ['CC','CCB']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index==1){
                        openWin('withdraw',{type:1});
                    }
                    if(index==2){
                        openWin('withdraw',{type:2});
                    }
                });
                },
                recharege(){
                    api.actionSheet({
                    title: '选择充值币种',
                    cancelTitle: '取消',
                    buttons: ['CC','CCB']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index==1){
                        openWin('address', {address:user.address});
                    }
                    if(index==2){
                        openWin('address', {address:user.tokenaddress});
                    }
                });
                }
            },
            created: function () {
            }
        })
    }

    function refresh() {
        if (getPrefs('token')) {
            var data = {
                member_id: getPrefs('member_id')
            };
            var callback = function (ret) {
                user = ret.content;
                qrcode = user.qrcode;
                setPrefs('user', user);

                if (vm) {
                    vm.user = user;

                    scanner.encodeImg({
                        content: qrcode,
                        saveImg: {
                            path: 'fs://qrcode.png',
                            w:400,
                            h:400
                        }
                    }, function (ret) {
                        vm.qrcode = {};
                        if(ret.status){
                            vm.qrcode = ret.imgPath;
                        }
                    });
                } else {
                    initApp();
                    api.parseTapmode();
                }
                api.refreshHeaderLoadDone();
            };
            var errback = function () {
                api.refreshHeaderLoadDone();
            };
            pinet.post(URL.getUserinfo, data, callback, errback);
        } else {
            api.refreshHeaderLoadDone();
        }

    }

    function addListeners() {
        api.addEventListener({
            name: 'upduser'
        }, refresh);

        api.addEventListener({
            name: 'reLogin'
        }, refresh);

        api.addEventListener({
            name: 'level_up'
        },
        function () {
            refresh();
        }
      );

        api.addEventListener({
            name: 'register'
        }, refresh);

        api.addEventListener({
            name: 'viewappear'
        }, function (ret, err) {
          if (getPrefs('token')) {
            user = JSON.parse(getPrefs('user'));
            if (user.hasPortraitUpd) {
                vm.user.portrait = user.portrait;
                user.hasPortraitUpd = false;
                setPrefs('user', user);
            }
          }
        });
    }

</script>
</html>